<template>
  <a-list
    class="atlas-list"
    row-key="id"
    item-layout="vertical"
    v-bind="$attrs"
    :data-source="dataSource"
  >
    <template #renderItem="{ item }">
      <a-list-item key="item.title">
        <template #actions>
          <a-space>
            <slot name="actions" :item="item"></slot>
          </a-space>
        </template>
        <template #extra>
          <a-image
            :width="300"
            :height="186"
            :alt="item.id"
            :src="item.imgUrl || noImg"
          />
        </template>
        <a-descriptions size="small" :column="3" bordered>
          <template #title>
            <div class="atlas-list__list-item-title-wrapper">
              <a-typography-text
                class="atlas-list__list-item-title"
                :ellipsis="{ tooltip: item.title }"
                :content="`${item.name || '暂无标题'}`"
              />
              <a-typography-text
                class="atlas-list__list-item-desc"
                :ellipsis="{ tooltip: item.description }"
                :content="`${item.description || '暂无描述'}`"
              />
            </div>
          </template>
          <a-descriptions-item label="ID">{{ item.id }}</a-descriptions-item>
          <a-descriptions-item label="素材类型">{{
            formatType(item.type, item.itype)
          }}</a-descriptions-item>
          <a-descriptions-item label="创建人">{{
            item.addUser
          }}</a-descriptions-item>
          <a-descriptions-item label="是否显示" :span="3">
            <RenderNode :v-node="formatAtlasShow(item.isShow || 0)" />
          </a-descriptions-item>
          <a-descriptions-item label="修改人">{{
            item.modifyUser
          }}</a-descriptions-item>
          <a-descriptions-item label="创建时间">{{
            formatTime(item.createTime, 'yyyy-MM-dd')
          }}</a-descriptions-item>
          <a-descriptions-item label="更新时间">{{
            formatTime(item.updateTime, 'yyyy-MM-dd')
          }}</a-descriptions-item>
          <a-descriptions-item label="标签" :span="3">
            <div class="atlas-list__tag-list">
              <RenderNode :v-node="formatTag(item.tags || [], 'tag')" />
            </div>
          </a-descriptions-item>
        </a-descriptions>
      </a-list-item>
    </template>
  </a-list>
</template>

<script setup lang="ts">
import type { AtlasItem } from '@/api/premium/content/model/atlasModel'
import { formatTime } from '@/utils/timeHelper'

import useFormat from '../hooks/useFormat'

import { RenderNode } from '@/components/Util'

defineProps<{
  dataSource: AtlasItem[]
}>()

const { formatTag, formatType, formatAtlasShow } = useFormat()
const noImg = 'https://dummyimage.com/600x400/e0e0e0/ffffff.jpg&text=+NO+IMG'
</script>

<style lang="scss" scoped>
@include b(atlas-list) {
  @include e(list-item-title-wrapper) {
    display: flex;
    align-items: baseline;
  }
  @include e(list-item-title) {
    max-width: 200px;
  }
  @include e(list-item-desc) {
    max-width: 500px;
    font-size: 12px;
    font-weight: 400;
    font-style: italic;
    margin-left: 8px;
    color: rgba(0, 0, 0, 0.45);
  }
  @include e(tag-list) {
    display: flex;
    width: 55vw;
    overflow-y: auto;
  }
}
</style>
<style lang="scss">
.atlas-list {
  .ant-list-item-extra {
    margin-right: 8px;
  }
  .ant-list-item {
    padding: 8px 0;
  }
  .ant-descriptions-bordered.ant-descriptions-small
    .ant-descriptions-item-label,
  .ant-descriptions-bordered.ant-descriptions-small
    .ant-descriptions-item-content {
    padding: 6px 8px;
  }
  .ant-descriptions-item-label {
    font-weight: 600;
    font-size: 12px;
  }
  .ant-descriptions-item-content {
    font-size: 12px;
  }
  .ant-descriptions-header{
    margin-bottom: 4px;
  }
  .ant-descriptions-title{
    font-size: 14px;
  }
  .ant-badge-status-text{
    font-size: 12px;
  }
}
</style>